var app = new Vue({
    el:'#app',
    data: {
        list:[
            {
                id:1,
                name:'iPhone 7',
                price:6188,
                count:1
            },{
                id:2,
                name:'vivo A67',
                price:1234,
                count:3
            },{
                id:3,
                name:'oppo x17',
                price:3214,
                count:1
            },{
                id:4,
                name:'mick 7',
                price:3241,
                count:2
            }
        ],
        pircked: 'js',
        pirckeds: ["js"],
        checks:["html","js"],
        radioEl:false,
        radioValue:123,
        toggle:'',
        value1:'789',
        value2:'456',
        message:''
    },
    computed: {
        totalPrice:function(){
            var total = 0;
            for (let i = 0; i < this.list.length; i++) {
               let item = this.list[i];
               total += item.price * item.count;
            }
            return total.toString().replace(/\B(?=(\d{3})+$)/g,',');
        }
    },
    methods:{
        handleReduce:function(index){
            if (this.list[index].count === 1) return;
            this.list[index].count -- ;
        },
        handleAdd:function(index){
            //if () return;
            this.list[index].count++;
        },
        handleRemove:function(index){
            this.list.splice(index,1);
        }

    }
});